package com.yanqu.road.server.cmd.activity.zhounianturntable;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.pb.activity.ZhouNianTurntableProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.zhounianturntable.ZhouNianTurntableModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_ZHOUNIAN_TURNTABLE_GET_RECORD, desc = "抽奖公告")
public class GetZhouNianTurntableRecordCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ActivityInfo activityInfo = player.getModule(ZhouNianTurntableModule.class).getInTimeOrPreviousActivity();
        if (activityInfo == null) {
            ret = GameErrorCode.E_ZHOUNIAN_TURNTABLE_NO_OPEN;
            return;
        }
        ZhouNianTurntableProto.CrossGetTurntableRecordReqMsg.Builder builder = ZhouNianTurntableProto.CrossGetTurntableRecordReqMsg.newBuilder();
        builder.setActivityId(activityInfo.getActivityId());
        builder.setServerId(GameServer.getInstance().getServerId());
        player.sendPacket(Protocol.C_ZHOUNIAN_TURNTABLE_ACTIVITY_GET_RECORD, builder);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ZhouNianTurntableProto.GetTurntableRecordRespMsg.Builder builder =  ZhouNianTurntableProto.GetTurntableRecordRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(Protocol.U_ZHOUNIAN_TURNTABLE_DRAW_RECORD, builder);
        }
    }
}
